package br.edu.infnet.avaliacao.controller;

import javax.servlet.http.HttpServletRequest;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.ioc.RequestScoped;
import br.edu.infnet.avaliacao.sessao.UsuarioWeb;

@Resource
@RequestScoped
public class IndexController {
	
	private Result result;
	private HttpServletRequest request;
	private UsuarioWeb usuarioWeb;
	
	public IndexController(Result result, HttpServletRequest request , UsuarioWeb usuarioWeb) {
		this.result = result;
		this.request = request;
		this.usuarioWeb = usuarioWeb;
	}
	
	@Path({"" , "/" , "index.jsp"})
	public void index()
	{

	}
	
	@Path("/login")
	public void login()
	{
		if (request.getRemoteUser() != null)
		{
			result.redirectTo(IndexController.class).index();
		}
	}
	
	@Path("/logout")
	public void logout()
	{
		request.getSession().invalidate();
        usuarioWeb.logout();
        result.redirectTo(IndexController.class).index();
	}

}
